<?php
/* SVN FILE: $Id: view.ctp 34 2009-10-17 13:42:12Z kenreily@gmail.com $ */
/**
 * Short description for file.
 *
 * Long description for file
 *
 * PHP versions 4 and 5
 *
 * Recenseo: Online submission and reviewing for education
 * Copyright 2008-2009, Ken Reily
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * $Date: 2009-10-17 13:42:12 +0000 (Sat, 17 Oct 2009) $
 * $Revision: 34 $
 * $Author: kenreily@gmail.com $
 * $HeadURL: http://recenseo.googlecode.com/svn/trunk/app/views/submissions/view.ctp $
 */

  if (!empty($submission))
  {
    $user = $session->read('Auth.User');
?>
<h4>Feedback on This Submission</h4>
<?php
    // User must complete all of their assessments before they can see their feedback.
    if ($user_asmts > 0) 
    {
?>
<p>You must <?= $html->link('complete your assessments',"/assessments/index/{$course['Course']['id']}") ?> in order to view your feedback.</p>
<?php
    }
    else
    {
?>
<table>
<?php
      echo $html->tableHeaders(array('Received','Score','Your Rating (out of 5)','Action'));
 
      if (count($assessments) > 0)
      {
        $all_rated = true;

        foreach ($assessments as $assessment)
        {
          if (empty($assessment['Assessment']['author_rating']))
          {
            $all_rated = false;
          }
        }

        foreach ($assessments as $assessment)
        {
          $score = $assessment['Assessment']['score'];

          if (empty($score) || !$all_rated)
          {
            $score = '-';
          }

          $action = $html->link('View',"/assessments/view/{$assessment['Assessment']['id']}");

          if (empty($assessment['Assessment']['author_rating']) && 
              $submission['Submission']['user_id'] == $user['id'])
          {
            $action = $html->link('Rate',"/assessments/rate/{$assessment['Assessment']['id']}");
          }

          $rating = $assessment['Assessment']['author_rating'];

          if (empty($rating))
	  {
            $rating = '(Not Yet Rated)';
          }
        
          echo $html->tableCells(array($assessment['Assessment']['submitted'],
                                       $score,
                                       $rating,
                                       $action),
                                 array('class' => 'altrow'));
        }                          
      }
      else
      {
?>
<tr><td colspan="4">No feedback available.</td></tr>
<?php
      }
?>
</table>
<?php
    }
?>
<h4>Submission Info</h4>
<dl>
  <dt>Submitted</dt>
  <dd><?php echo $time->nice($submission['Submission']['created']); ?></dd>
  
  <dt>Course</dt>
  <dd><?php echo $html->link($course['Course']['name'],'/assignments/index/' . $course['Course']['id']); ?></dd>
  
  <dt>Assignment</dt>
  <dd><?php echo $submission['Assignment']['name']; ?></dd>

  <dt>File</dt>
  <dd><?php echo $html->link($submission['Submission']['file_name'],'/submissions/download/' . $submission['Submission']['id']); ?></dd>
  
  <dt>Type</dt>
  <dd><?php echo $submission['Submission']['file_type']; ?>&nbsp;</dd>
  
  <dt>Size</dt>
  <dd><?php echo number_format($submission['Submission']['file_size'] / 1024,1) . 'kb'; ?></dd>
  
<?php
  if ($submission['Submission']['late_deduction_pct'] > 0)
  {
?>  
  <dt>Deduction</dt>
  <dd><?php echo $submission['Submission']['late_deduction_pct'] . '%'; ?></dd>
<?php
  }
  
  if (!empty($submission['GradingOption']['name']))
  {
?>
  <dt>Grading Option</dt>
  <dd><?php echo $submission['GradingOption']['name']; ?></dd>
<?php
  }
?>
  <dt>Comments</dt>
  <dd><?php echo $submission['Submission']['comments']; ?>&nbsp;</dd>
</dl>
<?php
    if (time() < strtotime($submission['Assignment']['due']))
    {
?>
<p>
<?php 
  echo $html->link(
    'Take back',
    '/submissions/resubmit/' . $submission['Submission']['id'],
    array(),
    'You are indicating that you wish to take this submission back. You will need to resubmit in order to get credit. Are you sure?'); 
?> this submission and resubmit.</p>
<?php
    }
  }
?>